#include<stdio.h>
#include<conio.h>
const int max = 1000000;
int m,n,s,f,c[10000][10000],d[1000];
int nHeap,heap[10000],h[10000];
int post[10000],free[10000],trace[1000];
int adj[10000],adjcost[10000];

void init(){
    int i,j;
    for(i=1;i<=n;i++){
        d[i]=max;
        for(j=1;j<=n;j++)
            c[i][j]=(i==j)?0:max;
    }
    nHeap=0;
    d[s]=0;
}
void input(){
    int i,u,v,l;
    FILE *fp=fopen("DIJKSTRA.INP","r");
    fscanf(fp,"%d%d%d%d",&n,&m,&s,&f);
    init();
    for(i=1;i<=m;i++){
        fscanf(fp,"%d%d%d",&u,&v,&l);
        h[u]++;
    }
    for(i=2;i<=n;i++)h[i]+=h[i-1];
    rewind(fp);
    fscanf(fp,"%d%d%d%d",&n,&m,&s,&f);
    for(i=1;i<=m;i++){
        fscanf(fp,"%d%d%d",&u,&v,&l);
        c[u][v]=c[v][u]=l;
        adj[h[u]]=v;
        adjcost[h[u]]=l;
        h[u]--;
    }
    h[n+1]=m;
    fclose(fp);
}
void update(int v){
    int chid=post[v],parent;
    if(chid==0)chid=++nHeap;
    parent=chid/2;
    while(parent>0 && d[heap[parent]]>d[v]){
        heap[chid]=heap[parent];
        post[heap[chid]]=chid;
        chid=parent;
        parent=chid/2;
    }
    heap[chid]=v;
    post[v]=chid;
}
int pop(){
    int r=1,c,v=heap[nHeap],ret=heap[1];
    nHeap--;
    while(2*r<=nHeap){
        c=2*r;
        if(c<nHeap && d[heap[c+1]]<d[heap[c]]) c++;
        if(d[v]<=d[heap[c]])break;
        heap[r]=heap[c];
        post[heap[r]]=r;
        r=c;
    }
    heap[r]=v;
    post[v]=r;
    return ret;
}
void dijkstra(){
    int i,u,iv,v,min;
    update(s);
    do{
        u=pop();
        if(u==f)break;
        free[u]=1;
        for(iv=h[u]+1;iv<=h[u+1];iv++){
            v=adj[iv];
            if(!free[v] && d[v]>d[u]+adjcost[iv]){
                d[v]=d[u]+adjcost[iv];
                trace[v]=u;
                update(v);
            }
        }
    }while(nHeap>0);
}
void output(){
    if(d[f]==max)printf(" No path");
    else{
        printf("Distance is %d\n",d[f]);
        while(s!=f){
            printf("%d <-- ",f);
            f=trace[f];
        }
        printf("%d",s);
    }
}
    
int main(){
    
    input();
    dijkstra();
    output();
    getch();
    return 0;
}
